// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import BulletScript from "./BulletScript";

const {ccclass, property} = cc._decorator;



@ccclass
export default class NewClass extends cc.Component {

    @property(cc.SpriteFrame)
    bulletIcon: cc.SpriteFrame = null;

    @property(cc.SpriteFrame)
    explodeEffect: cc.SpriteFrame = null;
    
    onLoad () {
        this.node.on('touchstart', this.startHandler, this)
    }

    start () {

    }

    startHandler(){
        console.log('aaa')
        if(this.bulletIcon === null) return;
        const bnode: cc.Node = new cc.Node();
        bnode.setScale(0.05)

        let sprite: cc.Sprite = bnode.addComponent(cc.Sprite);
        sprite.spriteFrame = this.bulletIcon;

        bnode.parent = this.node;

        bnode.setPosition( cc.v3(0, 50, 0) )

        // 添加脚本组件
        let script: BulletScript = bnode.addComponent( BulletScript )
        script.explodeEffect = this.explodeEffect;
    }

    // update (dt) {}
}